package sf.database.jdbc.type;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Types;

/**
 * 只能读,不可写入
 */
public class RefCursorType implements TypeHandler<ResultSet> {
    public ResultSet get(ResultSet rs, String columnName) throws SQLException {
        return rs.getObject(columnName, ResultSet.class);
    }

    public ResultSet get(ResultSet rs, int index) throws SQLException {
        return rs.getObject(index, ResultSet.class);
    }

    public ResultSet get(CallableStatement rs, int index) throws SQLException {
        return rs.getObject(index, ResultSet.class);
    }

    @Override
    public ResultSet get(CallableStatement cs, String parameterName) throws SQLException {
        return cs.getObject(parameterName, ResultSet.class);
    }

    @Override
    public void update(ResultSet rs, String columnLabel, Object value) throws SQLException {
        throw new SQLFeatureNotSupportedException("not support");
    }

    @Override
    public void update(ResultSet rs, int columnIndex, Object value) throws SQLException {
        throw new SQLFeatureNotSupportedException("not support");
    }

    public Object set(PreparedStatement stat, Object obj, int i) throws SQLException {
        throw new SQLFeatureNotSupportedException("not support");
    }

    @Override
    public Object set(CallableStatement cs, Object obj, String parameterName) throws SQLException {
        throw new SQLFeatureNotSupportedException("not support");
    }

    @Override
    public int getSqlType() {
        return Types.REF_CURSOR;
    }

    @Override
    public Class<ResultSet> getDefaultJavaType() {
        return ResultSet.class;
    }
}
